'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;
  router.get('/', controller.home.index);
  // 上传图片
  router.post('/api/upload', controller.upload.index);
  router.post('/api/login', controller.user.login);
  router.resources('goods', '/api/goods', app.middleware.checktoken(), controller.goods);
  router.resources('order', '/api/order', app.middleware.checktoken(), controller.order);
  router.resources('user', '/api/user', app.middleware.checktoken(), controller.user);
  router.resources('role', '/api/role', app.middleware.checktoken(), controller.role);
  router.resources('menu', '/api/menu', app.middleware.checktoken(), controller.menu);
  router.get('/api/searchGoods', controller.goods.searchGoodsList);
  router.get('/api/searchOrder', controller.order.searchOrderList);
  router.get('/api/orderCount', controller.order.getOrderCount);
  router.get('/api/shopTotal', controller.home.getShopTotalData);
  // 小程序前台页面数据接口*************************************************************************
  router.get('/newGoodsList', controller.goods.getNewGoodsData);
  router.get('/sellGoodsList', controller.goods.getSellGoodsData);
  // 综合
  router.get('/goodsListAll', controller.goods.getGoodsAllData);
  // 销量
  router.get('/goodsListSales', controller.goods.getGoodsSalesData);
  // 新品
  router.get('/goodsListNew', controller.goods.getGoodsNewData);
  // 价格
  router.get('/goodsListPrice', controller.goods.getGoodsPriceData);
  // 推荐商品（随机）
  router.get('/recommendGoods', controller.goods.getRecommendData);
  // 单个商品信息
  router.get('/goodsDetail/:id', controller.goods.getOneGoodsData);
  // 前台微信用户登录
  router.post('/wxlogin', controller.wxuser.login);
  // 前台用户下单
  router.post('/pay', app.middleware.checktoken(), controller.wxuser.pay);
  // 前台用户订单列表，根据用户id获取
  router.get('/wxorderList', app.middleware.checktoken(), controller.wxuser.getOrderListData);
  // 获取订单详情，根据订单ID获取
  router.get('/wxorderDetail/:id', app.middleware.checktoken(), controller.wxuser.getOrderDetailData);
  // 订单详情页相关操作
  router.put('/wxconfirmOrder/:id', app.middleware.checktoken(), controller.wxuser.confirmOrderData);
  router.put('/wxpayOrder/:id', app.middleware.checktoken(), controller.wxuser.payOrderData);
  router.delete('/wxdeleteOrder/:id', app.middleware.checktoken(), controller.wxuser.deleteOrderData);
};
